#ifndef __FUNC_H__
#define __FUNC_H__

#include <my_header.h>
//接收发送缓冲区大小
#define BUF_SIZE 1024
//命令中最多有几个参数
#define MAX_WORDNUM 8
//命令一个参数的最大长度
#define MAX_WORDLEN 30
// 100M文件大小限制
#define HUNDRED_MEGABYTE 104857600


typedef enum{
    TAGCD = 1,
    TAGLS,
    TAGREMOVE,
    TAGPWD,
    TAGMKDIR,
    TAGRMDIR,
    TAGGETS,
    TAGPUTS,
    TAG_RESPONSECD,
    TAG_RESPONSELS,
    TAG_RESPONSEREMOVE,
    TAG_RESPONSEPWD,
    TAG_RESPONSEMKDIR,
    TAG_RESPONSERMDIR,
    TAG_RESPONSEGETS,
    TAG_RESPONSEPUTS,

} Tag;

typedef int socket_t;

typedef struct train_s {
    int tag;
    int data_length;
    char data[BUF_SIZE];
} train_t, *ptrain_t;

//命令类型
typedef struct {
    int argc;       //命令中有几个参数
    char cmd[MAX_WORDNUM][MAX_WORDLEN];
} cmd_t, *pcmd_t;


int getValidStr(char *input, char *str);    
int getClientConf(char *fileconf, char *ip, char *port);
int login_client(int sockfd);
int epollAdd(int epfd, int fd);
int epollDel(int epfd, int fd);

void init_cmd(char *line, pcmd_t pcmd); //将line分割，存入cmd
void print_cmd(pcmd_t pcmd); //打印命令
int cmd_check(pcmd_t pcmd, int *ptag);//检查命令
// 接收服务端命令执行结果
int recv_ls(socket_t fd_server, ptrain_t ptrain);
int recv_pwd(socket_t fd_server, ptrain_t ptrain);
int recv_cd(socket_t fd_server, ptrain_t ptrain);
int recv_rm(socket_t fd_server, ptrain_t ptrain);
int recv_mkdir(socket_t fd_server, ptrain_t ptrain);
int recv_rmdir(socket_t fd_server, ptrain_t ptrain);
int recv_puts(socket_t fd_server, ptrain_t ptrain, pcmd_t pcmd);
int recv_gets(socket_t fd_server, ptrain_t ptrain, pcmd_t pcmd);
// 处理小文件
int send_file_train(int socket_fd, char *filename);
int get_filesize(char *filename /*, pdir_stack_t pdir_stack*/);
int recv_file_train(int fd_socket, char *filename);
// 处理大文件
int send_file_sendfile(int fd_client, char *filename, off_t filesize); 
#endif


